package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.vo.payment.ChangeInvoiceVo;
import com.ruoyi.training.vo.payment.InvoiceRefundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.Invoice;
import com.ruoyi.training.service.IInvoiceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 发票信息Controller
 * 
 * @author hcc
 * @date 2025-09-29
 */
@RestController
@RequestMapping("/invoice")
public class InvoiceController extends BaseController
{
    @Autowired
    private IInvoiceService invoiceService;

    /**
     * 查询发票信息列表
     */
    @RequiresPermissions("training:invoice:list")
    @GetMapping("/list")
    public TableDataInfo list(Invoice invoice)
    {
        startPage();
        List<Invoice> list = invoiceService.selectInvoiceList(invoice);
        return getDataTable(list);
    }

    /**
     * 导出发票信息列表
     */
    @RequiresPermissions("training:invoice:export")
    @Log(title = "发票信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Invoice invoice)
    {
        List<Invoice> list = invoiceService.selectInvoiceList(invoice);
        ExcelUtil<Invoice> util = new ExcelUtil<Invoice>(Invoice.class);
        util.exportExcel(response, list, "发票信息数据");
    }

    /**
     * 获取发票信息详细信息
     */
    @RequiresPermissions("training:invoice:query")
    @GetMapping(value = "/{invoiceId}")
    public AjaxResult getInfo(@PathVariable("invoiceId") String invoiceId)
    {
        return success(invoiceService.selectInvoiceByInvoiceId(invoiceId));
    }

    /**
     * 新增发票信息
     */
    @RequiresPermissions("training:invoice:add")
    @Log(title = "发票信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Invoice invoice)
    {
        return toAjax(invoiceService.insertInvoice(invoice));
    }

    /**
     * 修改发票信息
     */
    @RequiresPermissions("training:invoice:edit")
    @Log(title = "发票信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Invoice invoice)
    {
        return toAjax(invoiceService.updateInvoice(invoice));
    }

    /**
     * 删除发票信息
     */
    @RequiresPermissions("training:invoice:remove")
    @Log(title = "发票信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceIds}")
    public AjaxResult remove(@PathVariable String[] invoiceIds)
    {
        return toAjax(invoiceService.deleteInvoiceByInvoiceIds(invoiceIds));
    }

    /**
     * 获取退换票申请信息
     */
    @RequiresPermissions("training:invoice:query")
    @PostMapping(value = "/getInvoiceRefundInfo")
    public AjaxResult getInvoiceRefundInfo(@RequestBody InvoiceRefundVo invoiceRefundVo)
    {
        return success(invoiceService.getInvoiceRefundInfo(invoiceRefundVo));
    }

    /**
     * 批量修改发票状态
     */
    @RequiresPermissions("training:invoice:edit")
    @Log(title = "发票信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeInvoiceStatus")
    public AjaxResult changeInvoiceStatus(@RequestBody ChangeInvoiceVo changeInvoiceVo)
    {
        return toAjax(invoiceService.changeInvoiceStatus(changeInvoiceVo));
    }

    /**
     * 获取个人退换票申请信息
     */
    @RequiresPermissions("training:invoice:query")
    @GetMapping(value = "/getInvoiceRefundInfoPerson/{invoiceId}")
    public AjaxResult getInvoiceRefundInfoPerson(@PathVariable("invoiceId") String invoiceId)
    {
        return success(invoiceService.getInvoiceRefundInfoPerson(invoiceId));
    }
}
